﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Security;
using NLBS.Web;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NLBS.Data;
using System.Data.Common;

namespace NLBS.Install
{
   public class AccessInstallProvider:InstallProvider
    {
        public override void InitializeDataBase(string dataSource, string dataName, string userName, string password)
        {
           
        }

        public override bool TestCollection(string dataSource, string dataName, string userName, string password)
        {
            return true;
        }

        public override void InitBlog(string adminName, string adminPassword, string blogTitle)
        {
            User user = new User();
            user.UserName = adminName;
            user.Password = StringSecurity.StringToSHA1Hash(adminPassword);
            user.Homepage = string.Empty;
            user.Salt = "";
            user.IP = RequestWrapper.IP;
            user.Gender = 0;
            user.GroupID = 1;
            user.HideEmail = true;
            user.Email = "";
            user.LastVisit = DateTime.Now;
            DbProvider.Instance().InsertUser(user);
            Database database = DatabaseFactory.CreateDatabase();
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("update blog_settings set set_value1='{0}' where set_Name='blogTitle';", blogTitle);
            DbCommand dbCommand = database.GetSqlStringCommand(sb.ToString());
            database.ExecuteNonQuery(dbCommand);
        }
    }
}
